package com.itbbfx.service.warehourse.impl;

import com.itbbfx.entity.Baoque;
import com.itbbfx.mapper.BaoqueMapper;
import com.itbbfx.service.warehourse.BaoqueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaoqueServiceImpl implements BaoqueService {
    @Autowired
    private BaoqueMapper baoqueMapper;

    @Override
    public List<Baoque> queryAll(Baoque baoque) {
        return baoqueMapper.queryAll(baoque);
    }

    @Override
    public Baoque queryBaoque(String drugstoreName) {
        return baoqueMapper.queryBaoque(drugstoreName);
    }

    @Override
    public int clean(Baoque baoque, Integer jilunumber) {
        int baoqueNum = baoque.getBaoqueNum();
        if (baoqueNum <= jilunumber) {
            return baoqueMapper.delBaoque(baoque.getBaoqueid());
        }

        baoque.setBaoqueNum(baoqueNum - jilunumber);
        return baoqueMapper.updateBaoque(baoque);
    }
}